<?php

namespace app\api\controller;

use app\api\model\house\OrderCreate;
use app\common\controller\Api;

class Housegroupordercreate extends Api
{
    protected $noNeedRight = ['*'];


    //订单提交显示页
    public function calculate()
    {
        try {
            $order_create_model = new OrderCreate();
            $params = $this->request->param();
            $data = [
                'user_id'=>$this->auth->id,
                'house_id'=>input('house_id',0),
                'checkin_date'=>input('checkin_date',''),
                'leave_date'=>input('leave_date',''),
                'coupon_id'=>input('coupon_id',0),
                'complement_id'=>input('complement_id',[]),
            ];
            if (isset($params["complement_id"]) && !empty($params["complement_id"]) ){
                $data['complement_id'] = json_decode($params['complement_id'],true)?json_decode($params['complement_id'],true):_json_decode($params['complement_id']);
            } else {
                $data['complement_id'] = [];
            }

            if (isset($params["bed_occupant_id"]) && !empty($params["bed_occupant_id"]) ){
                $data['bed_occupant_id'] = json_decode($params['bed_occupant_id'],true)?json_decode($params['bed_occupant_id'],true):_json_decode($params['bed_occupant_id']);
            } else {
                $data['bed_occupant_id'] = [];
            }
            //dump($data);die;
            $res = $order_create_model->groupcalculate($data);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$res);
    }

    //提交订单
    public function create()
    {
        try {
            $order_create_model = new OrderCreate();
            $params = $this->request->param();

            $data = [
                'user_id'=>$this->auth->id,
                'house_id'=>input('house_id',0),
                'checkin_date'=>input('checkin_date',''),
                'leave_date'=>input('leave_date',''),
                'coupon_id'=>input('coupon_id',0),
                'complement_id'=>input('complement_id',[]),
            ];
            if (isset($params["complement_id"]) && !empty($params["complement_id"]) ){
                $data['complement_id'] = json_decode($params['complement_id'],true)?json_decode($params['complement_id'],true):_json_decode($params['complement_id']);
            } else {
                $data['complement_id'] = [];
            }

            if (isset($params["bed_occupant_id"]) && !empty($params["bed_occupant_id"]) ){
                $data['bed_occupant_id'] = json_decode($params['bed_occupant_id'],true)?json_decode($params['bed_occupant_id'],true):_json_decode($params['bed_occupant_id']);
            } else {
                $data['bed_occupant_id'] = [];
            }


            $res = $order_create_model->groupordercreate($data);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$res);
    }

}